package cn.com.cifi.mars.service.impl;

import java.time.LocalDateTime;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.com.cifi.mars.entity.SysJob;
import cn.com.cifi.mars.entity.SysJobRunHistory;
import cn.com.cifi.mars.mapper.mars.SysJobMapper;
import cn.com.cifi.mars.mapper.mars.SysJobRunHistoryMapper;
import cn.com.cifi.mars.service.SysJobService;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yyd
 * @since 2019-12-07
 */
@Service
public class SysJobServiceImpl extends ServiceImpl<SysJobMapper, SysJob> implements SysJobService {

	@Autowired
	private SysJobMapper sysJobMapper;
	
	@Autowired
	private SysJobRunHistoryMapper sysJobRunHistoryMapper;
	
	@Override
	public SysJob selectJobByCode(String code) {
		return sysJobMapper.selectJobByCode(code);
	}

	@Override
	public int lockJob(String code) {
		return sysJobMapper.lockJob(code);
	}
	
	@Override
	public int lockJobById(Integer jobId) {
		return sysJobMapper.lockJobById(jobId);
	}
	
	@Override
	public int resetJob(SysJob job,LocalDateTime start,LocalDateTime end) {
		SysJobRunHistory jobHistory=new SysJobRunHistory();
		jobHistory.setBeginTime(start);
		jobHistory.setEndTime(end);
		jobHistory.setJobId(job.getId());
		jobHistory.setName(job.getName());
		sysJobRunHistoryMapper.insert(jobHistory);
		return sysJobMapper.resetJob(job.getId());
	}

	@Override
	public int resetStatus(SysJob job) {
		return sysJobMapper.resetJob(job.getId());
	}
	
	
}
